package com.example.passwordmanager.db;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.RoomWarnings;
import androidx.room.Update;

import java.util.List;

@Dao
public interface UserDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertUserBean(UserBean... userBeans);


    @Update(onConflict = OnConflictStrategy.REPLACE)
    int updateUserBean(UserBean... userBeans);

    @Delete
    void deleteUserBean(UserBean... userBeans);



    @Query("SELECT * FROM user")
    List<UserBean> loadAllUserBean();

    @Query("SELECT * FROM user")
    LiveData<List<UserBean>> loadLiveDataOfAllUserBean();

    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
    @Query("SELECT id,name,username,password,secretKey FROM user")
    LiveData<List<UserBean>> loadLiveDataOfAllUser();

    @Query("SELECT * FROM user WHERE id=:id")
    UserBean getUserById(int id);


    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
    @Query("SELECT id,name,username,password,secretKey FROM user WHERE name Like '%'||:sname||'%'")
    LiveData<List<UserBean>> vagueSearchForName(String sname);


}
